Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 5403 - improvements for "price adding" #5404

Closed

Conversation

monsieurtanuki
Copy link
Contributor

What

Improvements about price adding:

  • when we add a product, now we focus on its "paid price" text field
  • now we don't display the "add product" button when the product list only has the empty product
  • we don't accept twice the same product
  • now there's a "remember my choice during this session" checkbox regarding automatic server look-up after scan

Bug fix:

  • confusion with the amounts when we remove a product (typical flutter key issue)

Screenshot

unique barcode no "add product" button at start remember my choice
Screenshot_1718730706 Screenshot_1718730671 Screenshot_1718730619

Part of

Impacted files

  • app_en.arb: added a "remember my choice" and a "barcode already there" labels
  • app_fr.arb: added a "remember my choice" and a "barcode already there" labels
  • price_amount_card.dart: now using a focus node and a key; stronger resilience
  • price_amount_field.dart: now using a focus node
  • price_amount_model.dart: minor refactoring
  • price_model.dart: new getBarcodes method
  • price_product_search_page.dart: now managing a list of existing barcodes; now storing at session level the answer of the "server look-up?" question
  • product_price_add_page.dart: now manages a focus on the latest added product, and keys for item deletion; not displaying the "add product" button if irrelevant

Impacted files:
* `app_en.arb`: added a "remember my choice" and a "barcode already there" labels
* `app_fr.arb`: added a "remember my choice" and a "barcode already there" labels
* `price_amount_card.dart`: now using a focus node and a `key`; stronger resilience
* `price_amount_field.dart`: now using a focus node
* `price_amount_model.dart`: minor refactoring
* `price_model.dart`: new `getBarcodes` method
* `price_product_search_page.dart`: now managing a list of existing barcodes; now storing at session level the answer of the "server look-up?" question
* `product_price_add_page.dart`: now manages a focus on the latest added product, and keys for item deletion; not displaying the "add product" button if irrelevant
Copy link
Collaborator

@g123k g123k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 change requested

  • 1 minor comment :)

@override
void initState() {
super.initState();
_controllerPaid.text = _model.paidPrice;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's risky to change the text this way, as the setter may notify a client calling setState… and we're already in the dirty state.

To prevent any issue, I would just wrap it around a addPostFrameCallback

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I've double-checked and I can't see how this could happen:

  • the only setter in this line is _controllerPaid.text
  • .text doesn't trigger anything, in particular not onChanged
  • besides, it's in the initState, when the widget isn't even built, so no setState expected.

That said, if you prefer a safer way (reviewing-wise) to do exactly the same thing, would you like me to rewrite it like that:

  late final TextEditingController _controllerPaid;
  late final TextEditingController _controllerWithoutDiscount;

  @override
  void initState() {
    super.initState();
    _controllerPaid = TextEditingController(text: _model.paidPrice);
    _controllerWithoutDiscount =
        TextEditingController(text: _model.priceWithoutDiscount);
  }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A TextEditingController is a ValueNotifier and text is linked the value.
Hence the dependency to listeners

return SmoothCard(
child: Column(
children: <Widget>[
Text(
'${appLocalizations.prices_amount_subtitle}'
'${widget.total == 1 ? '' : ' (${widget.index + 1}/${widget.total})'}',
'${_total == 1 ? '' : ' (${widget.index + 1}/$_total)'}',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not mandatoryuu here, but an improvement would be to use NumberFormat, because some languages has specific way to handle separators

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I think you read a bit quickly: here it's not a division (with a decimal separator), it's a lousy "current_item_number/total_number_of_items" description (like "step 1/3").
I'm not proud of that but it's helpful for a user to know where he is among the products.
I couldn't find anything about that in NumberFormat - though they probably display that differently depending on the countries.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and no.
My point is not on the /, but how you format the numbers between the /

@monsieurtanuki
Copy link
Contributor Author

Thank you @g123k for your comments, it made me go back to the flutter docs and realize that I forgot the dispose calls.
I've just added them in the latest push.

As for your latest comments, I guess you've reached the limits of my understanding: I cannot picture in which language a number like 5 wouldn't be understood (OK Japanese people also use but they do understand 5), and a TextEditingController won't notify an object that doesn't exist yet.

Feel free to amend this PR or to close it.

Meanwhile, I convert it to "Draft".

@monsieurtanuki monsieurtanuki marked this pull request as draft June 20, 2024 13:59
@codecov-commenter
Copy link

codecov-commenter commented Jun 29, 2024

Codecov Report

Attention: Patch coverage is 0% with 93 lines in your changes missing coverage. Please review.

Project coverage is 6.94%. Comparing base (4d9c7fc) to head (5fb06b8).
Report is 284 commits behind head on develop.

Files Patch % Lines
...pp/lib/pages/prices/price_product_search_page.dart 0.00% 35 Missing ⚠️
...smooth_app/lib/pages/prices/price_amount_card.dart 0.00% 28 Missing ⚠️
...h_app/lib/pages/prices/product_price_add_page.dart 0.00% 22 Missing ⚠️
...kages/smooth_app/lib/pages/prices/price_model.dart 0.00% 4 Missing ⚠️
...mooth_app/lib/pages/prices/price_amount_model.dart 0.00% 3 Missing ⚠️
...mooth_app/lib/pages/prices/price_amount_field.dart 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           develop   #5404      +/-   ##
==========================================
- Coverage     9.54%   6.94%   -2.61%     
==========================================
  Files          325     399      +74     
  Lines        16411   21203    +4792     
==========================================
- Hits          1567    1473      -94     
- Misses       14844   19730    +4886     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@teolemon teolemon added the ✨ enhancement New feature or request label Aug 1, 2024
@monsieurtanuki
Copy link
Contributor Author

Closing as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request Prices
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants